<div id="content-wrapper" class="corner">
<?php slot('title',sprintf('CorpPon - Shopping Cart ')) ?>

<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr class="titulos-cart">
    <td class="titulo-cart">Product Name</td>
    <td  class="titulo-cart">Unit Price</td>
    <td  class="titulo-cart">Qty</td>
    <td  class="titulo-cart">Subtotal</td>
    <td  class="titulo-cart">Drop</td>
    <td class="titulo-cart" colspan="2">Update Shopping Cart</td>
  </tr>
  <?php

  $color =array("#ffffff","#F0F0F0");
  $contador = 0;
  $sum = 0;
  
  $itemCompra="";

  foreach($cart as $array => $cart_param) :

    $subto = $cart_param['quantity']*$cart_param['product_price'];
    $sum = $sum + $subto;
    $contador++;
    $price = $cart_param['product_price'];
    $product_name = $cart_param['product_name'] ;
    $product_description = $cart_param['product_description'] ;
    $product_quantity = $cart_param['quantity'];
    $product_id = $cart_param['id_product'] ;
    $shipping_price = $cart_param['shipping_price'] ;

    //$shipping_total += $shipping_price*$product_quantity;
		//Concatemacion de item
    $itemCompra.='<input type="hidden" name="product[]" value="'.implode(',',array('id_product' => $product_id, 'quantity' => $product_quantity)).'">';
    //$itemCompra.='<input type="hidden" name="product[]" value="'.$contador.'" />';
      ?>
  <form name="a<?php echo $cart_param['id'] ?>" method="post" action="<?php echo url_for('products/addToCart') ?>" id="a<?php echo $cart_param['id'] ?>">
    <tr bgcolor="<?php echo $color[$contador%2]; ?>" class='prod'>
      <td class="item-cart"><input type="hidden" name="product_name" id="product_name" value="<?=$product_name?>" /><?=$product_name?></td>
      <td class="item-cart"><input type="hidden" name="product_price" id="product_price" value="<?=$price?>" />$<?=$price?> </td>
      <td class="item-cart"><input type="text" name="product_quantity" id="product_quantity" size="1" value="<?php echo $cart_param['quantity'] ?>" /></td>
      <td class="item-cart"><input type="hidden" name="company" id="company_url" value="<?=$sf_params->get('companyNameUrl')?>" />
        <input name="id_product" type="hidden" id="id_product" value="<?php echo $product_id ?>">
        <input name="shipping_price" type="hidden" id="shipping_price" value="<?php echo $shipping_price ?>">
        $<?php echo number_format($cart_param['quantity']*$price,2) ?>
      </td>
     <td class="item-cart">
        <a href="<?php echo url_for('products/removeFromCart?company='.$sf_params->get('companyNameUrl').'&id_product='.$cart_param['id']) ?>"><img src="/images/cart/trash.gif" border="0" alt="trash"></a>
      </td>
      <td class="item-cart">
        <input name="imageField" type="image" src="/images/cart/actualizar.gif">
      </td>
    </tr>
  </form>
  <?php
  endforeach;


//Importe de la compra
$amount 		= number_format($sum,2);
$freight		="1.00";
$shipping_total = Doctrine_Core::getTable('ShippingAmount')->getShippingAmount(number_format($sum,2));
//$shipping_total = $shipping_amount->getAmount();

?>
    <tr>
      <td colspan="3"><span class="legenda-cart">Total Products:</span> <?php echo count($cart); ?></td>
      <td colspan="3">
    	<span class="legenda-cart">Subtotal:</span> $<?php echo number_format($sum,2); ?>
      </td>
    </tr>
    <tr>
      <td colspan="3"></td>
      <td colspan="3">
    	<span class="legenda-cart">Shipping:</span> $<?php echo number_format($shipping_total,2); ?>
      </td>
    </tr>
    <tr>
      <td colspan="3"></td>
      <td colspan="3">
    	<span class="legenda-cart">Total: </span>
      $<?php
      //$total_invoice_amount = $sum + $shipping_total;
      $total_invoice_amount = $sum + $shipping_total;
      echo number_format($total_invoice_amount,2); ?>
      </td>
    </tr>
    <tr>
      <td colspan="3" ><a href="<?php if ($sf_params->get('companyNameUrl')) : echo '/'.$sf_params->get('companyNameUrl'); else : echo url_for('@homepage'); endif; ?>">Back to home
        
            
	</a>
      </td>
      <td colspan="3" align="center">
	<form method="post" id="formCheckout" action="<?php echo url_for('invoices/checkoutCredit'); ?>" >
        <input type='hidden' name="amount" value="<?php echo $total_invoice_amount; ?>" />
        <?php echo $itemCompra; ?>
        <input type="hidden" name="shipping" id="shipping" value="<?php echo $shipping_total ?>" />
        <?php if ($sf_params->get('id_invoice')) : ?>
           <input type="hidden" name="id_invoice" id="id_invoice" value="<?php echo $sf_params->get('id_invoice') ?>" />
        <?php endif; ?>
        <?php if (!$sf_user->isAuthenticated()) : ?>
        <img alt="paypal" src="/images/cart/bt_comprar.jpg" style="background-image:url(/images/cart/bt_comprar.jpg); cursor:pointer" onclick="alert('You have to log in')" />
        <?php else : ?>
        <input type="image" src="/images/cart/bt_comprar.jpg" style="background-image:url(/images/cart/bt_comprar.jpg); cursor:pointer" value="Process" <?php if ($contador == 0) : echo 'onclick="alert(\'You do not have any product\'); return false;"'; endif; ?>  />

        
        <?php endif; /*?>
        </form>

        <form method="post" id="formCheckout" action="<?php echo url_for('invoices/checkout') ?>" >
        <input type='hidden' name="amount" value="<?php echo $total_invoice_amount; ?>" />
        <?php echo $itemCompra; ?>
        <input type="hidden" name="shipping" id="shipping" value="<?php echo $shipping_total ?>" />
        <?php if (!$sf_user->isAuthenticated()) : ?>
        <img alt="paypal" src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" style="cursor:pointer" onclick="alert('You have to log in')" />
        <?php else : ?>
        <input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" />
        <?php endif; */?>
        </form>
      </td>
    </tr>
</table>
</div>